package com.ecahack.busstop.data;

import org.json.JSONException;
import org.json.JSONObject;

public class BusinessObjectFactory {

	// BusStop fields description
	private static final String DESCRIPTION = "Description"; 
	private static final String DISTANCE = "Distance";
	private static final String LATITUDE = "Latitude";
	private static final String LONGITUDE = "Longitude";
	private static final String LOCATION_ID = "LocationID";
	
	// Bus fields description
	private static final String BUS_NUMBER = "BusNumber";
	private static final String DESTINATION = "Destination";
	private static final String MINUTES = "Minutes";

	public static BusStop createBusStopFromJSON(JSONObject jsonBusStop) throws JSONException {
		String desc = jsonBusStop.getString(DESCRIPTION);
		float distance = (float) jsonBusStop.getDouble(DISTANCE);
		double latitude = jsonBusStop.getDouble(LATITUDE);
		double longitude = jsonBusStop.getDouble(LONGITUDE);
		String locationId = jsonBusStop.getString(LOCATION_ID);
		
		BusStop busStop = new BusStop();
		busStop.setId(System.currentTimeMillis()); // XXX
		busStop.setDescription(desc);
		busStop.setDistance(distance);
		busStop.setLatitude(latitude);
		busStop.setLongitude(longitude);
		busStop.setLocationId(locationId);
		return busStop;
	}

	public static Bus createBusFromJSON(JSONObject jsonBus) throws JSONException {
		String number = jsonBus.getString(BUS_NUMBER);
		String destination = jsonBus.getString(DESTINATION);
		String minutes = jsonBus.getString(MINUTES);
		
		Bus bus = new Bus();
		bus.setNumber(number);  // XXX number da time stringebi? WTF
		bus.setLastStop(destination); // lastStop <-> destination ratom vurevt saxelebs :(
		bus.setTime(minutes);
		return bus;
	}
	
}
